***********************************
*Code to replicate the findings in Hsiung and Djupe (forthcoming) in Political Behavior
*File contains code for the cross-sectional dataset
*Date: 3/22/2018
*Dataverse location: URL HERE.
***********************************

*Use the csv datafile - change the appropriate file location
import delimited "C:\Users\pdjup\Dropbox\Trust\Trust R&R\Clean Data\completes.csv"

*Dependent Variables - Political and Social Trust
gen ptrust=q16_1 // I trust the federal government to do what is right, 1=SD, 5=SA
gen strust=6-q16_5 // You can't be too careful in trusting others, 1=SA, 5=SD
la var ptrust "Political Trust"
la var strust "Social Trust"

*Communitarian values
gen communitarian=q38-1 // which did you try to do more: avoid doing sinful things yourself=0 or help other people=1?
la var communitarian "Communitarian values"

*Devil Exists
gen devil=(5-q34_3)/4 // The devil actually exists. 1=SD, 5=SA
la var devil "Devil exists"

*Religious salience
gen rsal=q33
la var rsal "Rel. salience"

*Inclusive and Exclusive values (higher is more)
foreach x in 1 2 3 4 {
gen q35_`x'r=6-q35_`x'
}
gen inclusive=(q35_1r+q35_4r)/2
gen exclusive=(q35_2r+q35_3r)/2
la var inclusive "Inclusive values"
la var exclusive "Exclusive values"

*Worship attendance 1=Never, 6=Weekly+
gen relattr=7-q32
la var relattr "Rel. attendance"

*Religious Engagement
egen releng=anycount(q36_4 q36_8 q36_9), values(1)
la var releng "Rel. engagement"

*Political Church 
egen polch=anycount(q36_2 q36_5 q36_7), values(1)
la var polch "Political Church"

*Religious Traditions
gen rt_ev=0
replace rt_ev=1 if (q31==1 | q31==5) & q34_1<3
replace rt_ev=0 if q45_2==1
gen rt_mp=0
replace rt_mp=1 if (q31==1 | q31==5) & q34_1>2
gen rt_bp=0
replace rt_bp=1 if q45_2==1 & (q31==1 | q31==5)
gen rt_cath=0
replace rt_cath=1 if q31==2
gen rt_none=0
replace rt_none=1 if q31>8
gen rt_other=0
replace rt_other=1 if q31==3 | q31==4 | q31==6 | q31==7 | q31==8
la var rt_ev "Evangelical"
la var rt_mp "Mainline Prot."
la var rt_bp "Black Prot."
la var rt_cath "Catholic"
la var rt_none "Rel. None"
la var rt_other "Rel. Other"

gen reltrad=0
replace reltrad=1 if rt_mp==1
replace reltrad=2 if rt_ev==1
replace reltrad=3 if rt_cath==1
replace reltrad=4 if rt_bp==1
replace reltrad=5 if rt_other==1
replace reltrad=6 if rt_none==1

*Political Activity Scale
egen polact=anycount(q42_*), values(1)
la var polact "Political Activity"

*Female=1, Male=0
gen female=q43-1
la var female "Female"

*Education level
gen ed=q50
la var ed "Education"

*Age in years
gen age=2012-q46
la var age "Age"

*Partisanship, 7pt
gen pid=q48
la var pid "Partisanship"

*White
recode q45_1 (.=0), gen(white)
la var white "White"

*Religiosity
gen religiosity=(((6-q32)/5)+(q33-1)/3)/2


*Figure 1 - coefplot of p and s trust, less the interactions
reg ptrust communitarian rsal exclusive inclusive relattr devil releng polch rt_ev rt_bp rt_cath rt_none rt_other polact female ed age pid white
	estimates store ptrust
reg strust communitarian rsal exclusive inclusive relattr devil releng polch rt_ev rt_bp rt_cath rt_none rt_other polact female ed age pid white
	estimates store strust	
coefplot ptrust, bylabel("Political Trust") || strust, bylabel("Social Trust") drop (_cons) xline(0) scheme(s1mono) ci(90 95) ciop(recast(rcap rspike)) 

*Table A.2, Political Trust, with the interactions
reg ptrust communitarian rsal exclusive c.inclusive##c.relattr c.devil##c.inclusive c.releng##c.polch rt_ev rt_bp rt_cath rt_none rt_other polact female ed age pid white
	outreg2 using table_a2.doc, dec(2) stats(coef pval) side

*Figure 2 - Inclusive Values Only Change the Political Trust of More Infrequent Worship Attenders
margins, at(inclusive=(1(1)5) relattr=(1 5)) l(76)
marginsplot, xlabels(1 `""Not""Inclusive""' 5 `""Very""Inclusive""') ytitle("Political Trust") graphregion(color(white)) ///
	legend(order(3 "No Attendance" 4 "Weekly+ Attendance") region(color(white))) title("") xscale(range(1 5.1)) ///
	plot1op(lc(black) mc(black)) plot2op(lc(black) lp(dash) ms(Sh) mc(black)) ciopt(lc(gs10))

*Figure 3 - Politics in Church without Church Collective Action Impedes Political Trust 
margins, at(releng=(0(1)3) polch=(0 3)) l(76)
marginsplot, xlabels(0 `""None of the""Activities""' 3 `""All of the""Activities""') ytitle("Political Trust") xtitle("Religious Engagement") graphregion(color(white)) ///
	legend(order(3 "Non-Political" 4 "Political Church") region(color(white))) title("") xscale(range(1 3.1)) ///
	plot1op(lc(black) mc(black)) plot2op(lc(black) lp(dash) ms(Sh) mc(black)) ciopt(lc(gs10))

	
*Table A.2, Social Trust, with the interactions
reg strust communitarian rsal exclusive c.inclusive##c.relattr c.devil##c.inclusive c.releng##c.polch rt_ev rt_bp rt_cath rt_none rt_other polact female ed age pid white
	outreg2 using table_a2.doc, dec(2) stats(coef pval) side

save data.dta
	
*Figure A.1 - Political and Social Trust Levels of Major Religious Traditions (90% CIs)
statsby pt=r(mean), saving("ptsum.dta", replace) by(reltrad): sum ptrust
statsby st=r(mean), saving("stsum.dta", replace) by(reltrad): sum strust
statsby up_pt90=r(ub) lo_pt90=r(lb), saving("pt90.dta", replace) by(reltrad): ci means ptrust, l(90)
statsby up_st90=r(ub) lo_st90=r(lb), saving("st90.dta", replace) by(reltrad): ci means strust, l(90)

use ptsum.dta, clear
merge 1:1 reltrad using stsum.dta
drop _merge
merge 1:1 reltrad using pt90.dta
drop _merge
merge 1:1 reltrad using st90.dta
la def reltrad 1 "M" 2 "E" 3 "C" 4 "B" 5 "O" 6 "N" 
la val reltrad reltrad


twoway rspike up_pt90 lo_pt90 st ///
	|| rspike up_st90 lo_st90 pt, hor ///
	|| scatter pt st, legend(off) scheme(s1mono) mlab(reltrad) mlabpos(2) ///
	ytitle("Political Trust") xtitle("Social Trust")


*Figure A.2 - Distribution of Political and Social Trust Across Levels of Worship Attendance and Religious Activities
use data.dta, clear
reg ptrust i.releng
margins, at(releng=(0(1)3)) l(90)
marginsplot, plotop(lc(black)) ciopt(lc(black) mc(black)) ytitle("Political Trust") /// 
	xtitle("Religious Engagement") legend(off) xlabels(0 1 2 3) ///
	addplot(scatter ptrust releng, jitter(20) ms(oh) mc(gs10) below) graphregion(color(white)) ///
	name(ptrust_engage, replace) title("")

reg ptrust i.relattr
margins, at(relattr=(1(1)6)) l(90)
marginsplot, plotop(lc(black)) ciopt(lc(black) mc(black)) ytitle("Political Trust") /// 
	xtitle("Religious Attendance") legend(off) xlabels(1"Never" 2 3 4 5 6 "Weekly") ///
	addplot(scatter ptrust relattr, jitter(20) ms(oh) mc(gs10) below) graphregion(color(white)) ///
	name(ptrust_attend, replace) title("")
	

reg strust i.releng
margins, at(releng=(0(1)3)) l(90)
marginsplot, plotop(lc(black)) ciopt(lc(black) mc(black)) ytitle("Social Trust") /// 
	xtitle("Religious Engagement") legend(off) xlabels(0 1 2 3) ///
	addplot(scatter strust releng, jitter(20) ms(oh) mc(gs10) below) graphregion(color(white)) ///
	name(strust_engage, replace) title("")

reg strust i.relattr
margins, at(relattr=(1(1)6)) l(90)
marginsplot, plotop(lc(black)) ciopt(lc(black) mc(black)) ytitle("Social Trust") /// 
	xtitle("Religious Attendance") legend(off) xlabels(1"Never" 2 3 4 5 6 "Weekly") ///
	addplot(scatter strust relattr, jitter(20) ms(oh) mc(gs10) below) graphregion(color(white)) ///
	name(strust_attend, replace) title("")
	
graph combine ptrust_engage ptrust_attend strust_engage strust_attend, graphregion(color(white))

*Figure A.3 - Those Who Believe in the Devil are Consistently Less Trusting...
gen devil1=(devil-1)/4
reg ptrust c.devil1##c.relattr communitarian rsal inclusive exclusive c.releng##c.polch rt_ev rt_bp rt_cath rt_none rt_other polact female ed age pid white
margins, dydx(devil1) at(relattr=(1(1)6)) l(90)
marginsplot, scheme(s1mono) xlabels(1 `""No""Attendance""' 2 3 4 5 6 `""Weekly+""Attendance""') xscale(range(1 6.2)) ytitle("") title("") name(att, replace) nodraw yline(0, lp(dash))
reg ptrust c.devil1##c.inclusive communitarian rsal relattr exclusive c.releng##c.polch rt_ev rt_bp rt_cath rt_none rt_other polact female ed age pid white
margins, dydx(devil1) at(inclusive=(1(1)5)) l(90)
marginsplot, scheme(s1mono) xlabels(1 `""Not""Inclusive""' 2 3 4 5 `""Very""Inclusive""') xscale(range(1 5.2)) ytitle("Political Trust") title("") name(inc, replace) nodraw yline(0, lp(dash))

graph combine inc att, xsize(4) ysize(2) scheme(s1mono)

*Figure A.4 - The Distribution of Political Church Attendance by Religiosity and White Evangelical Status
egen relig_pc_ep_mean=mean(religiosity), by(polch rt_ev)
sort polch
twoway scatter religiosity polch if rt_ev==0, ms(oh) mlc(gs10) jitter(20) xtitle("Political Church Level") ///
	|| scatter  religiosity polch if rt_ev==1, ms(o) mc(gs10) jitter(20) ///
	|| connected relig_pc_ep_mean polch if rt_ev==0, lp(dash) lc(black) mc(black) ms(Oh) ///
	|| connected relig_pc_ep_mean polch if rt_ev==1, lp(solid) lc(black) mc(black) ///
	ytitle("Religiosity") legend(order(1 "Non-Evangelical" 2 "Evangelical" 3 "Non-Evangelical Mean" 4 "Evangelical Mean") region(color(white))) graphregion(color(white))

*Figure A.5 Marginal Effects of Being in a Political Church on Perceiving Political Disagreement in Church Conditional on Congregational Engagement
recode q36_3(2=0),gen(disagch)
gen polch1=(polch/3)
logit disagch c.polch1##c.releng  rsal inclusive exclusive rt_ev rt_bp rt_cath rt_none rt_other female ed age pid white
margins, dydx(polch1) at(releng=(0(1)3)) l(90)
marginsplot, yline(0, lc(red)) scheme(s1mono) ytitle("Probability of Disagreement at my Church") xtitle("Religious Engagement") title("")
	